﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

using Newtonsoft.Json.Serialization;

using ProjectBase.Core;

using $prjsn$.Entity;

namespace $safeprojectname$
{
    /// <summary>
    /// Converts the IList[entity] into array of their IDs
    /// </summary>
    public class ChildrenValueProvider : IValueProvider
    {
        readonly PropertyInfo _childrenPropertyInfo;
        public ChildrenValueProvider(PropertyInfo childrenPropertyInfo)
        {
            _childrenPropertyInfo = childrenPropertyInfo;
        }
        public void SetValue(object target, object value)
        {
            throw new NotImplementedException();
        }

        public object GetValue(object target)
        {
            var value = _childrenPropertyInfo.GetValue(target, null);
            var children = value as IEnumerable<ICodeList>;

            return children.Is()
                       ? children.Select(c => c.ID).ToArray()
                       : null;

        }
    }
}